<?php
    //开启Session 
    session_start();
    include './public/db_object.php';

    if(isset($_POST)){
        $name = $_POST['name'];
        $pass = $_POST['pass'];
        
        $db = new DB_object(['db_name'=>'db_shop']);
        $sql = "select * from user where name='".$name."'";
        //echo $sql;
        $res_name = $db->l_select_one($sql);
        if(empty($res_name)){
            echo 0; // 用户不存在
            exit;
        }
        $salt = $res_name['salt'];
        
        $new_pass = md5($pass.$salt);
        if($new_pass == $res_name['pass']){
            echo 1; // 登录成功
            $_SESSION['user_name'] = $name;
        }else{
            echo 2; // 密码错误
        }
        // echo "<pre>";
        // var_dump($res_name);
    }


?>